// Copyright (c) 2022 NetEase, Inc. All rights reserved.
// Use of this source code is governed by a MIT license that can be
// found in the LICENSE file.

package com.netease.yunxin.kit.qchatkit.ui.server;

import android.content.Intent;
import android.os.Bundle;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.Nullable;
import com.netease.yunxin.kit.common.ui.activities.BaseActivity;
import com.netease.yunxin.kit.qchatkit.ui.R;
import com.netease.yunxin.kit.qchatkit.ui.databinding.QChatCreateServerWayActivityBinding;

/** 创建/加入圈组社区的选择入口 */
public class QChatCreateWayActivity extends BaseActivity {

  private QChatCreateServerWayActivityBinding binding;
  private ActivityResultLauncher<Intent> launcher;

  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = QChatCreateServerWayActivityBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());

    launcher =
        registerForActivityResult(
            new ActivityResultContracts.StartActivityForResult(),
            result -> {
              if (result.getResultCode() == RESULT_OK) {
                finish();
              }
            });
    initView();
  }

  private void initView() {
    binding.tvClose.setOnClickListener(v -> finish());
    // 创建普通社区
    binding.tvCreateSelf.setOnClickListener(
        v -> {
          QChatCreateBySelfActivity.launch(launcher, QChatCreateWayActivity.this, false);
          overridePendingTransition(R.anim.anim_from_end_to_start, R.anim.anim_empty_with_time);
        });
    // 查询及加入普通社区
    binding.tvJoinOther.setOnClickListener(
        v -> {
          QChatJoinOtherServerActivity.launch(launcher, QChatCreateWayActivity.this, false);
          overridePendingTransition(R.anim.anim_from_end_to_start, R.anim.anim_empty_with_time);
        });

    // 创建公告频道
    binding.tvCreateSelfAnnounce.setOnClickListener(
        v -> {
          QChatCreateBySelfActivity.launch(launcher, QChatCreateWayActivity.this, true);
          overridePendingTransition(R.anim.anim_from_end_to_start, R.anim.anim_empty_with_time);
        });
    // 查询及加入公告频道
    binding.tvJoinOtherAnnounce.setOnClickListener(
        v -> {
          QChatJoinOtherServerActivity.launch(launcher, QChatCreateWayActivity.this, true);
          overridePendingTransition(R.anim.anim_from_end_to_start, R.anim.anim_empty_with_time);
        });
  }

  @Override
  public void finish() {
    super.finish();
    overridePendingTransition(R.anim.anim_empty_with_time, R.anim.anim_from_top_to_bottom);
  }
}
